use "$replication\data\for_NSS.dta", clear

global Regress_terms "elec_m*   elec_p*   ROADxelec_m*   ROADxelec_p*"
global Rcontrols " i.ROAD#c.ln_pc01_pca_tot_p i.ROAD#c.ln_pc01_pca_tot_p_m i.ROAD#c.ln_dwelling_area i.ROAD#c.ln_dwelling_area_m i.ROAD#c.ln_land_possessed i.ROAD#c.ln_land_possessed_m i.ROAD#c.tdist_10 i.ROAD#c.tdist_10_m i.ROAD#c.tdist_50 i.ROAD#c.tdist_50_m i.ROAD#c.sc_share i.ROAD#c.sc_share_m i.ROAD#c.st_share i.ROAD#c.st_share_m i.ROAD#c.lit_share i.ROAD#c.lit_share_m i.ROAD#c.religion_code_* i.ROAD#c.social_group_code_* i.ROAD#c.land_possessed_code_code_*"

foreach var of varlist elec_cons_share NCO_ag ln_HH_cons  ln_HH_cons_kharif  ln_HH_cons_rabi {	
		qui {
		global column=1+$column
		reghdfe `var' $Regress_terms   $Rcontrols , absorb(i.ROAD#i.year#i.d_id  i.ROAD#c.HH_size_*) cluster(FSU_wave)  poolsize(30)
		
		estimates store `var'
		estimates store main_regression
		
		cap drop sample
		gen sample=e(sample)
		global elec_list "0"
		global Relec_list "0"
		forval i=0/5 {
			sum elec_p`i' if elec==1 & sample , mean
			global elec_list "$elec_list +`r(mean)'*elec_p`i'"
			sum ROADxelec_p`i' if elec==1 & sample & ROAD==1, mean
			global Relec_list "$Relec_list +`r(mean)'*ROADxelec_p`i'"
		}
		disp "`var', `s'"
		disp "$elec_list"
		
		estimates restore main_regression
		}
		lincom "$elec_list"
		lincom "$Relec_list"
		
		
	
}